package com.zb.user.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjUserTypeKnowledgeTypeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.UserKnowledgeTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户分类知识库分类关联表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-11-14
 */
@Api(tags = "用户分类知识库类型权限接口")
@RestController
@RequestMapping("/user/type/knowledge/type")
public class ZjUserTypeKnowledgeTypeController {
    @Resource
    private ZjUserTypeKnowledgeTypeService userTypeKnowledgeTypeService;

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "客户设置 - 用户分类 - 修改用户分类知识库权限")
    @ApiOperation("修改用户知识库权限")
    @PostMapping("/save/{userTypeId}")
    public Result save(HttpServletRequest request, @PathVariable @ApiParam(value = "客户分类ID", required = true) Long userTypeId,
                       @RequestBody UserKnowledgeTypeVo userKnowledgeTypeVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        userTypeKnowledgeTypeService.save(custAccId, userTypeId, userKnowledgeTypeVo);
        return Result.success("修改用户知识库权限成功");
    }

    @ApiOperation("根据客户分类ID获取知识库类型权限列表")
    @PostMapping("/getList/{userTypeId}")
    public Result getList(@PathVariable @ApiParam(value = "客户分类ID", required = true) Long userTypeId, @RequestBody PageUtil pageUtil) {
        return Result.success("获取知识库类型权限列表成功").data(userTypeKnowledgeTypeService.getList(userTypeId, pageUtil));
    }

}
